//
//  OMGoodDetailRecommendCollectCell.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2017/4/19.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMGoodDetailRecommendCollectCell.h"
#import "OMProduct.h"
@implementation OMGoodDetailRecommendCollectCell

- (void)configureWithFakeData:(OMFakeGoodData *)fakeGood
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        UIImage *image = [UIImage imageNamed:fakeGood.image];
        dispatch_async(dispatch_get_main_queue(), ^{
            [_goodIconImageView setImage:image];
        });
    });
    _nameLabel.text = [fakeGood.image stringByReplacingOccurrencesOfString:@".jpg" withString:@""];
    _specLabel.text = fakeGood.spec;
    _priceLabel.text = [NSString stringWithFormat:@"￥%@",fakeGood.price];
}

- (void)configure
{
    [super configure];
    self.specLabel.font = SM_CFont(24);
}

- (void)didSelectBasketButton:(UIButton *)button
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickPlusButton:withProduct:)]) {
        [self.delegate didClickPlusButton:button withProduct:self.product];
    }
}


- (void)configureCellWithObj:(OMProduct *)product
{
    self.product = product;
    [self.goodIconImageView kt_imageWithURLStr:product.image placeHolder:[UIImage imageNamed:@"homepage-loading-260-260"] withSize:CGSizeMake(self.goodIconImageView.size.width*3, self.goodIconImageView.size.height*3)];
    NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString: product.brand.length?[NSString stringWithFormat:@"[%@]",product.brand]:@"" attributes:@{NSFontAttributeName:SM_CFont(28)}];
    !title.string.length?:[title appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
    [title appendAttributedString:[[NSAttributedString alloc] initWithString:product.name?:@"" attributes:@{NSFontAttributeName:SM_CFont(27)}]];
    _brandLabel.attributedText = title;
    _specLabel.text = product.unit?:@" ";
    _priceLabel.text = product.price.floatValue == 0 ?@"线上预约": [[NSString stringWithFormat:@"￥%.2f",product.price.floatValue]  stringByReplacingOccurrencesOfString:@".00" withString:@""];

    if (product.promotions.count) {
        self.tagButton.hidden = NO;
        [self.tagButton setTitle:product.promotions.firstObject.name forState:UIControlStateNormal];
    }else {
        self.tagButton.hidden = YES;
    }
}

@end
